<%@ taglib uri="http://www.rapid-framework.org.cn/rapid" prefix="rapid"%>
<%@ page language="java" import="java.util.*"
	contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<rapid:override name="frame-header-style">
	<link rel="stylesheet" href="resources/css/index-page.css">
</rapid:override>

<rapid:override name="frame-header-script">
	<script type="text/javascript" src="resources/js/jquery.min.js"></script>
	<script>
	$(function(){
		
		
		//判断分类名称是否存在
		$("#categoryName").blur(categoryNam);
		function categoryNam(){
			var r=false;
			var reg=/^[^\s]{1,20}$/;
			if( !reg.test($("#categoryName").val()) ){
				$("#categoryName_msg").html("用户名不合法.请输入1-20位字符");
				return r;
			}
			$.ajax({
				url:"category/yzCateName",
				type:"POST",
				data:{categoryName:$("#categoryName").val()},
				async:false,
				cache:false,
				dataType:"text",
				success:function(str){
					if(str==0){//没有该名字
						$("#categoryName_msg").html("*");
						r=true;
					}else{
						$("#categoryName_msg").html("该名称已被占用");
					}
				}
			});
			return r;
		}
		
		//添加
		$("#subm").click(function(){
			var r=true;
			$("#categoryPid").val("1");
			if(!categoryNam()){
				r=false;
			}
			
			if(r){
				r=confirm("确定修改吗");
			}
			return r;
		});
		
		
		//回显下拉框
		var pid=$("#cdId").val();
		if(pid>0){
			$("#pid").val(pid)
		}
		
	});
	</script>
</rapid:override>

<rapid:override name="frame-content">
<div style="padding: 15px;">
	<blockquote class="layui-elem-quote">
		<span class="layui-breadcrumb" lay-separator="/"> 
			<a href="Login">首页</a> 
			<a href="category/allCate">分类列表</a> 
			<a><cite>修改分类</cite></a>
		</span>
	</blockquote>

	<div class="layui-row">
		<div class="layui-col-md4">
			<form class="layui-form" method="post" id="myForm" action="category/updateCate">
				<input type="hidden" name="categoryId" value="${category.categoryId }" />
				<div class="layui-form-item">
					<div class="layui-input-block">
						<strong>添加分类</strong>
					</div>
					<div class="layui-input-block">
						名称
						 <span id="categoryName_msg" style="color: #FF5722;">*</span> 
						<input type="text" id="categoryName" name="categoryName" value="${category.categoryName }" placeholder="请输入分类名称" autocomplete="off" class="layui-input" required>
					</div>
					<br>
					
					<div class="layui-input-block">
						父节点 <span style="color: #FF5722;">*</span> 
						<input type="hidden" id="cdId" value="${category.categoryPid}" />
						<select id="pid" name="categoryPid" class="layui-input">
							<option value="0">无</option>
							<c:forEach var="pc" items="${pCategoryList }">
								<option value="${pc.categoryId }" <c:if test="${category.categoryPid==pc.categoryId}">selected</c:if> >${pc.categoryName }</option>
							</c:forEach>
						</select>
					</div>
				
					<br>
					<div class="layui-input-block">
						分类描述 
						<input type="text" name="categoryDescription" value="${category.categoryDescription }" placeholder="请输入分类描述" autocomplete="off" class="layui-input">
					</div>
					
					<br>
					<div class="layui-input-block">
						图标样式 <input type="text" name="categoryIcon" value="${category.categoryIcon }" placeholder="请输入图标样式,如 fa fa-coffee" autocomplete="off" class="layui-input">
					</div>
					
					<br>
					<div class="layui-input-block">
						<button id="subm" class="layui-btn" lay-filter="formDemo" type="submit">修改</button>
						<span>${msg }</span>
					</div>
				</div>
			</form>
		</div>
		<div class="layui-col-md8">
			<table class="layui-table">
				<colgroup>
					<col width="300">
					<col width="100">
					<col width="100">
					<col width="100">
					<col width="50">
					<col width="50">
				</colgroup>
				<thead>
					<tr>
						<th>名称</th>
						<th>文章数</th>
						<th>操作</th>
						<th>ID</th>
						<th>pid</th>
					</tr>
				</thead>
				<tbody>
					<c:forEach var="c" items="${categoryList }">
						<tr>
							<td>
								<a href="category/getCateById/${c.categoryId }" target="_blank">${c.categoryName }</a>
							</td>
							<td>
								<a href="category/getArticlesByCateId/${c.categoryId }" target="_blank">${c.articleCount }</a>
							</td>
							<td>
								<a href="category/edit/${c.categoryId }" class="layui-btn layui-btn-mini">编辑</a> 
								<c:if test="${c.articleCount==0 }">
									<a href="category/deleteCateById/${c.categoryId }" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirm('确定删除吗')">删除</a>
								</c:if>
							</td>
							<td class="cate-parent">${c.categoryId }</td>
							<td>${c.categoryPid }</td>
						</tr>
						<c:forEach var="cc" items="${c.chileCategory }">
							<tr>
								<td>
									<a href="category/getCateById/${cc.categoryId }" target="_blank">——${cc.categoryName }</a>
								</td>
								<td>
									<a href="category/getArticlesByCateId/${cc.categoryId }" target="_blank">${cc.articleCount }</a>
								</td>
								<td>
									<a href="category/edit/${cc.categoryId }" class="layui-btn layui-btn-mini">编辑</a> 
									<c:if test="${cc.articleCount==0 }">
										<a href="category/deleteCateById/${cc.categoryId }" class="layui-btn layui-btn-danger layui-btn-mini" onclick="return confirmDelete()">删除</a>
									</c:if>
								</td>
								<td class="cate-parent">${cc.categoryId }</td>
								<td>${cc.categoryPid }</td>
							</tr>
						</c:forEach>
					</c:forEach>
				</tbody>
			</table>
			<blockquote class="layui-elem-quote layui-quote-nm">
				温馨提示：
				<ul>
					<li>分类最多只有两级，一级分类pid=0，二级分类pid=其父节点id</li>
					<li>如果该分类包含文章，将不可删除</li>
				</ul>
			</blockquote>
		</div>
	</div>

</div>
</rapid:override>

<%@ include file="../framework.jsp" %>